﻿--1客户
--2供应商
--3员工
--4其它
CREATE VIEW [dbo].[ASMS_V_CapitalIncreaseBill]
	AS 
SELECT CIB.*,
	MDIIT.Name as InvoiceTypeName,
case CIB.PayerRoleType
	when 1 then (select C.[Name] from ASMS_Customer as C where C.Id = CIB.PayerRole)
    when 2 then (select S.[Name] from ASMS_Supplier as S where S.Id = CIB.PayerRole)
    when 3 then (select STAFF.[Name] from ASMS_Staff as STAFF where STAFF.Id = CIB.PayerRole)
	else CIB.PayerRole 
	end as PayerRoleName
FROM ASMS_CapitalIncreaseBill as CIB
	left join ASMS_MasterDataItem as MDIIT on MDIIT.Code = CIB.InvoiceType